package com.etogc.groupchat.common;

import com.alibaba.fastjson.JSONObject;
import com.etogc.util.SpUtil;

/**
 * Created by zv on 2017-12-6.
 */

public class CommonSp {

    public static boolean isWxLogin() {
        String result = SpUtil.getInstance().getString("IS_WX_LOGIN", "false");
        return Boolean.parseBoolean(result);
    }

    public static void setIsWxLogin(boolean isWxLogin) {
        SpUtil.getInstance().putString("IS_WX_LOGIN", String.valueOf(isWxLogin));
    }

    public static boolean canRecvMessage() {
        String result = SpUtil.getInstance().getString("CAN_RECV_MSG", "true");
        return Boolean.parseBoolean(result);
    }

    public static void setCanRecvMessge(boolean canRecvMessage) {
        SpUtil.getInstance().putString("CAN_RECV_MSG", String.valueOf(canRecvMessage));
    }

    public static void setUserInfo(String userInfo) {
        SpUtil.getInstance().putString("USER_INFO", userInfo);
    }

    public static String getUserInfo() {
        String json = SpUtil.getInstance().getString("USER_INFO");
        if (!"".equals(json)) {
            JSONObject jo = JSONObject.parseObject(json);
            json = jo.toJSONString();
        }
        return json;
    }

    public static void setData(String data) {
        SpUtil.getInstance().putString("DATA", data);
    }

    public static String getData() {
        return SpUtil.getInstance().getString("DATA");
    }

    // 1 不是第一次 0 第一次
    public static void setFirst(String isFirstLogin) {
        SpUtil.getInstance().putString("IS_FIRST", isFirstLogin);
    }

    public static boolean isFirst() {
        String first = SpUtil.getInstance().getString("IS_FIRST", "0");
        return "0".equals(first);
    }

    public static void setPhone(String phone) {
        SpUtil.getInstance().putString("PHONE", phone);
    }

    public static String getPhone() {
        return SpUtil.getInstance().getString("PHONE", "");
    }

    public static void setToken(String token) {
        SpUtil.getInstance().putString("TOKEN", token);
    }

    public static String getToken() {
        return SpUtil.getInstance().getString("TOKEN", "");
    }

    public static void setRongToken(String rongToken) {
        SpUtil.getInstance().putString("RONG_TOKEN", rongToken);
    }

    public static String getRongToken() {
        return SpUtil.getInstance().getString("RONG_TOKEN", "");
    }

    public static void setUserID(String userID) {
        SpUtil.getInstance().putString("USER_ID", userID);
    }

    public static String getUserID() {
        return SpUtil.getInstance().getString("USER_ID", "");
    }


    public static void setNickName(String nickName) {
        SpUtil.getInstance().putString("NICK_NAME", nickName);
    }

    public static void setLoginType(String loginType) {
        SpUtil.getInstance().putString("LOGIN_TYPE", loginType);
    }

    public static String getLoginType() {
        return SpUtil.getInstance().getString("LOGIN_TYPE", "");
    }

    public static String getNickName() {
        return SpUtil.getInstance().getString("NICK_NAME", "用户");
    }

    public static void setHeadUrl(String headUrl) {
        SpUtil.getInstance().putString("HEAD_URL", headUrl);
    }

    public static String getHeadUrl() {
        return SpUtil.getInstance().getString("HEAD_URL", "");
    }

    //
    public static void setIsMaster(String is_master) {
        SpUtil.getInstance().putString("IS_MASTER", is_master);
    }

    public static boolean isMaster() {
        String first = SpUtil.getInstance().getString("IS_MASTER", "0");
        return "0".equals(first);
    }
}
